package com.tkr.controller.home;

import com.tkr.entity.ResouceContent;
import com.tkr.entity.ResouceContentWithBLOBs;
import com.tkr.entity.ResouceLable;
import com.tkr.entity.SiteConfig;
import com.tkr.service.ResouceContentService;
import com.tkr.service.ResouceLableService;
import com.tkr.service.SiteConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("home")
public class IndexController {


    @Autowired
    private SiteConfigService siteConfigService;
    @Autowired
    private ResouceContentService resouceContentService;
    @Autowired
    private ResouceLableService resouceLableService;

    @RequestMapping("toIndex")
    public String toIndex(){
        return "index";
    }

    @PostMapping("/index")
    @ResponseBody
    public Map<String,Object> index(ModelMap modelMap){
        Map<String,Object> map = new HashMap<>();
        ResouceContentWithBLOBs resouceContent = new ResouceContentWithBLOBs();
        SiteConfig siteConfig = siteConfigService.select();
        resouceContent.setIsRecommend(1);
        List<ResouceContentWithBLOBs> contentList = resouceContentService.selectEntity(resouceContent);
        ResouceLable resouceLable = new  ResouceLable();
        List<ResouceLable> resouceLables = resouceLableService.selectEntity(resouceLable);
        List<ResouceContentWithBLOBs> clickCount = resouceContentService.SelectClickCount();
        modelMap.put("siteConfig",siteConfig);
        modelMap.put("contentList",contentList);
        modelMap.put("resouceLables",resouceLables);
        modelMap.put("clickCount",clickCount);
        return map;
    }
}
